<style>
    .ivu-table{
        font-size:12px !important;
    }
</style>
<template>
    <compWrapper
        v-if="hasWrapper"
        :title="$t('global.common.operate_history')"
        theme="gray"
    >
        <slot></slot>
        <Table
            class="margin-15"
            :columns="getColumns"
            :data="getData"
            :loading="loading"
            border
        ></Table>
        <slot name="footer" slot="footer"></slot>
    </compWrapper>
    <Table
        v-else
        class="margin-15"
        :columns="getColumns"
        :data="getData"
        :loading="loading"
        border
    ></Table>
</template>
<script>
export default {
    props: {
        // 'data', 'wrapper', 'ajaxRequest', 'params',
        data: Array,
        columns: Array,
        wrapper: Boolean,
        ajaxRequest: Function,
        params: Object,
        opActionMap: Object
    },
    // components: {
    //     compWrapper: () => import("./wrapper")
    // },
    data() {
        return {
            dataList: [],
            loading: false
        };
    },
    created() {
        this.getLogList();
    },
    methods: {
        getLogList() {
            if (typeof this.ajaxRequest === "function") {
                this.loading = true;
                this.ajaxRequest(this.params).then(
                    res => {
                        this.loading = false;
                        this.dataList = res.data || [];
                    },
                    err => {
                        this.loading = false;
                        this.$Message.error(err.message);
                    }
                );
            }
        }
    },
    computed: {
        // log 类型转换
        getLogActionMap() {
            // PUSH_WAREHOUSE(1,"推送仓库"),
            // CANCEL_PUSH_WAREHOUSE(2,"取消推送仓库"),
            // TRACKING_PUSH_WAREHOUSE(3,"tracking推送仓库"),
            // WRITE_BACK_BOSS(4,"回传boss"),
            // WRITE_BACK_FBB(5,"回写云仓"),
            // INVENTORY_TASK_WRITE_BACK(6,"库存变动回写boss"),
            // INVENTORY_TASK_WRITE_BACK_VIRTUAL(7,"库存变动回写虚拟库存模块"),
            // CHECK(8,"审核"),
            // PUSH_ATTACH(9,"推送附件"),

            // WMS_WRITE_BACK_FBB(10,"wms回传fbb"),
            // WAREHOUSEDOCKING_WRITE_BACK_FBB(11,"warehousedocking回传fbb")
            // ETURN_TRACKING(4,"tracking回写Boss"),
            // PUSH_ATTACH(10,"推送附件"),
            // OPERATE_TYPE_TASK_WRITE_BACK_NEW(13,"库存流水回写"),
            // UN_ACTIVE(90,"失效"),
            // CREATE(100,"创建"),
            // UPDATE(200,"更新"),
            // SUBMIT(210,"提交"),
            // SAVE_SUBMIT(230,"保存并提交"),
            // CANCEL_APPLY(240,"撤回申请"),
            // SAVE(250,"保存"),
            // EDIT(260,"编辑"),
            // DISCHARGE(290,"卸货"),
            // DELETED(300,"删除"),
            // CANCEL(400,"取消"),
            // CHECK_APPROVE(500,"审核通过"),
            // CHECK_REFUSE(600,"审核拒绝"),
            // PUSH_DASHBOARD(610,"BOSS处理"),
            // OUTBOUNDED(710,"已出库"),
            // GEN_BOXLABEL(830,"生成箱标"),
            // ORDER_PUSH_WAREHOUSE(930,"推送仓库");
            return (
                this.opActionMap || {
                    // '1': "推送仓",
                    // '2': "取消推送仓库",
                    // '3': "tracking推送仓库",
                    "4": this.$ct('fbb.alloment.tracking_rewrite_boss', { defaultValue: "tracking回写Boss" }),
                    // '5': "回写云仓",
                    // '6': "库存变动回写boss",
                    // '7': "库存变动回写虚拟库存模块",
                    // '8': "审核",
                    // '9': "推送附件",
                    // '10': "wms回传fbb",
                    // '11': "warehousedocking回传fbb",
                    "10": this.$ct('fbb.alloment.push_attachment', { defaultValue: "推送附件" }),
                    "13": this.$ct('fbb.alloment.stock_write_back', { defaultValue: "库存流水回写" }),
                    "24": '买面单',
                    "90": this.$ct('fbb.alloment.loss_effect', { defaultValue: "失效" }),
                    "100": this.$ct('global.common.create', { defaultValue: "创建" }),
                    "200": this.$ct('fbb.alloment.update	', { defaultValue: "更新" }),
                    "210": this.$ct('global.common.update_submit	', { defaultValue: "提交" }),
                    "215": this.$ct('fbb.alloment.cancel_audit', { defaultValue: "撤销审核" }),
                    "230": this.$ct('fbb.alloment.save_and_commit', { defaultValue: "保存并提交" }),
                    "240": this.$ct('fbb.alloment.back_apply', { defaultValue: "撤回申请" }),
                    "250": this.$ct('global.common.save', { defaultValue: "保存" }),
                    "260": this.$ct('global.common.edit', { defaultValue: "编辑" }),
                    "290": this.$ct('fbb.reserveinbound.discharge', { defaultValue: "卸货" }),
                    "300": this.$ct('global.common.delete', { defaultValue: "删除" }),
                    "310": "获取面单",
                    "400": this.$ct('global.common.operate_cancel', { defaultValue: "取消" }),
                    "500": this.$ct('fbb.inbound.pass_audit', { defaultValue: "审核通过" }),
                    "600": this.$ct('fbb.alloment.refuse_audit', { defaultValue: "审核拒回" }),
                    "610": this.$ct('fbb.alloment.boss_deal_with', { defaultValue: "BOSS处理" }),
                    "710": this.$ct('fbb.alloment.has_outbound', { defaultValue: "已出库" }),
                    "720": this.$ct('global.datepicker.confirm', { defaultValue: "确认" }),
                    "730": this.$t('erp.aftersales.buyfaceorder', { defaultValue: "购买面单" }),
                    "740": '取消面单',
                    "800": this.$ct('global.common.finished', { defaultValue: "已完成" }),
                    "830": this.$ct('fbb.inbound.rawcrates_standard', { defaultValue: "生成箱标" }),
                    "930": this.$ct('fbb.alloment.push_warehouse', { defaultValue: "推送仓库" }),
                    "935": this.$ct('fbb.alloment.cancel_push_warehouse', { defaultValue: "取消推送仓库" }),
                    "940": this.$ct('fbb.alloment.action_oredr_push_warehouse', { defaultValue: "执行单推送仓库" }),
                    "945": this.$ct('fbb.alloment.finish_push_warehouse', { defaultValue: "完成推送仓库" }),
                    "1010": this.$ct('fbb.alloment.inbound_back_boss', { defaultValue: "调拨入库执行单回传boss" }),
                    "1073": this.$ct('fbb.inbound.common_warehouse_rewrite', { defaultValue: "仓库回写" }),
                }
            );
        },
        hasWrapper() {
            return this.wrapper || this.$slots.footer || this.$slots.default;
        },
        getData() {
            return this.data || this.dataList;
        },
        getColumns() {
            if (this.columns && this.columns.length > 0) return this.columns;
            return [
                {
                    title: this.$ct("global.common.operator"),
                    key: "createdName"
                    // render(h, { row }) {
                    // 	return row.createdName || row.updatedName;
                    // },
                },
                {
                    title: this.$ct("global.common.operate_time"),
                    key: "createdAt"
                },
                {
                    title: this.$ct("global.common.operate_remark", {
                        defaultValue: "备注"
                    }),
                    key: "opRemark",
                    render: (h, { row }) => {
                        const value = row.opAction || row.operateType || row.action;
                        return (
                            <div>
                                <div>
                                    {this.$ct("global.common.operate_type")}:
                                    {this.getLogActionMap[value] || value}
                                </div>
                                <div>
                                    {this.$ct("global.common.operate_note")}:
                                    {row.opRemark || row.remark || row.opResult}
                                </div>
                                <div>
                                    {this.$t("global.common.actions")}数据:
                                    {row.opData || '--'}
                                </div>
                            </div>
                        );
                    }
                }
            ];
        }
    }
};
</script>
